package com.jk.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jk.entity.*;
import com.jk.service.BalanceService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("app/balance")
public class BalanceController {

    @Resource
    private BalanceService balanceService;

    @PostMapping
    @RequestMapping("/addcard")
    public String addcard(@RequestBody BankInfo bankInfo){

        balanceService.addcard(bankInfo);

        return "新增成功";
    }


    /**
     * 充值
     * @return
     * leeslus@icloud.com
     */
    @PutMapping
    @RequestMapping("/saverecharge")
    public Message saverecharge(@RequestParam Integer  rechargenum){

        Recharge recharge=new Recharge();

        recharge.setRechargenum(rechargenum);

        Message message =  balanceService.saverecharge(recharge);

        return message;
    }

    /**
     *查询积分
     * @param integral
     * @return
     */
    @PostMapping
    @RequestMapping("/queryintegral")
    public Message queryintegral(@RequestBody Integral integral) {

        Message message  = balanceService.queryintegral(integral);

        return  message;
    }

    /**
     *查询银行卡信息
     * @return
     */
    @GetMapping
    @RequestMapping("/querycardinfo")
    public String querycardinfo(){

        Userinfo userinfo = new Userinfo();

        userinfo.setUserid("44bdd8f03f1411e8");

        Userinfo list =  balanceService.querycardinfo(userinfo);

        System.out.println(userinfo);
        System.out.println(list+"2222222");

        return JSON.toJSONString(list);
    }

    /**
     * 查询用户信息
     * @param
     * @return√
     */
    @GetMapping
    @RequestMapping(value = "/queryuserinfo",method = RequestMethod.GET)
    public String queryuserinfo(){

      /*
       HttpServletRequest request,HttpServletResponse response
       response.setCharacterEncoding("utf-8");
        String jsonp = request.getParameter("jsonp");
        String offset = request.getParameter("offset");,offset,limit
        String limit = request.getParameter("limit");*/

        Userinfo userinfo = new Userinfo();

        userinfo.setRegisterid("6abeef823d7511e8ad7d00163e32baaa");

        List<Userinfo> list =  balanceService.queryuserinfo(userinfo);

        HashMap hs=new HashMap();

        hs.put("rows",list);

        String str = JSON.toJSONString(hs);

        System.out.println(str);

        return str;
    }

    /**
     * 查询余额接口
     * @return
     */
    @GetMapping
    @RequestMapping("/querybalance")
    public  String querybalance(){

        Balance balance=new Balance();

        balance.setUserid("44bdd8f03f1411e8");

        List<Balance> list  =   balanceService.querybalance(balance);

        HashMap hs=new HashMap();

        hs.put("rows",list);

        String str = JSON.toJSONString(hs);

        return str;
    }
}
